package dungeon;

import border.Door;
import square.Direction;
import square.Square;
import square.TeleportationSquare;


/**
 * A class for creating shafts, as a type of dungeon that has fixed coordinates in two directions.
 * 
 * @invar	Each square can have the given square as one of its squares.
 * 			| canHaveAsSquare(square)
 * 
 * @version	3.0
 * @author 	Inge Gielis <inge.gielis@student.kuleuven.be>
 * @author	Annelies ketelslegers <annelies.ketelslegers@student.kuleuven.be
 */
public class Shaft<E extends Square> extends LeafDungeon<E> {

	/**
	 * Initialize this new shaft with the given values as the maximum values for the coordinates
	 * of the positions of teleportation squares in this shaft.
	 * 
	 * @param 	maxX
	 * 			The maximum value for the x coordinate of a position in a shaft.
	 * @param 	maxY
	 * 			The maximum value for the Y coordinate of a position in a shaft.
	 * @param 	maxZ
	 * 			The maximum value for the Z coordinate of a position in a shaft.
	 * 
	 * @throws 	IllegalArgumentException
	 * 			The given maximum coordinates are invalid coordinates for a shaft.
	 * 			At least two out of the three given coordinates must be zero to create a valid shaft.
	 * 			| !((maxX == 0 && maxY == 0) || (maxX == 0 && maxZ == 0) || (maxY == 0 && maxZ == 0))
	 */
	public Shaft(long maxX, long maxY, long maxZ) throws IllegalArgumentException{
		super(maxX, maxY, maxZ);
		if(!((maxX == 0 && maxY == 0) || (maxX == 0 && maxZ == 0) || (maxY == 0 && maxZ == 0)))
			throw new IllegalArgumentException("The given maximum coordinates are invalid coordinates for a shaft!");
	}
	/**
	 * Check whether this shaft can have the given square as one of its squares.
	 * 
	 * @param	square
	 * 			The square to check.
	 * 
	 * @return	False if this method defined at the level of the superclass is not true.
	 * 			| if(! super.canHaveAsSquare(square))
	 * 			|	then result == false
	 * @return	False if the given square is not a teleportation square.
	 * 			| if(! square instanceof TeleportationSquare)
	 * 			|	then result == false
	 * @return	If the maximum x coordinate for teleportation squares is zero, true if the given square does not have
	 * 			doors in its east or west direction.
	 * 			| if(getMaxXCoordinate() != 0)
	 * 			|	if(!(square.getBorder(Direction.EAST) instanceof Door && square.getBorder(Direction.WEST) instanceof Door))
	 * 			|		then result == true
	 * @return	If the maximum y coordinate for teleportation squares is zero, true if the given square does not have
	 * 			doors in its north or south direction.
	 * 			| if(getMaxYCoordinate() != 0)
	 * 			|	if(!(square.getBorder(Direction.NORTH) instanceof Door && square.getBorder(Direction.SOUTH) instanceof Door))
	 * 			|		then result == true
	 * @return	If the maximum z coordinate for teleportation squares is zero, true if the given square does not have
	 * 			doors in its floor or ceiling direction.
	 * 			| if(getMaxZCoordinate() != 0)
	 * 			|	if(!(square.getBorder(Direction.FLOOR) instanceof Door && square.getBorder(Direction.CEILING) instanceof Door))
	 * 			|		then result == true
	 */
	@Override
	public boolean canHaveAsSquare(E square){
		if(! super.canHaveAsSquare(square))
			return false;
		if(! (square instanceof TeleportationSquare))
			return false;
		if(getMaxXCoordinate() != 0)
			if(!(square.getBorder(Direction.EAST) instanceof Door && square.getBorder(Direction.WEST) instanceof Door))
				return true;
		if(getMaxYCoordinate() != 0)
			if(!(square.getBorder(Direction.NORTH) instanceof Door && square.getBorder(Direction.SOUTH) instanceof Door))
				return true;
		if(getMaxZCoordinate() != 0)
			if(!(square.getBorder(Direction.FLOOR) instanceof Door && square.getBorder(Direction.CEILING) instanceof Door))
				return true;
		return false;
	}
	

}
